package china.accountinghelper.activity;

import com.xdroid.base.AsyncTaskBase;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import china.wc.tallyhelper.R;
import china.wc.tallyhelper.adapter.AdapterListViewBookList;
import china.wc.tallyhelper.controls.SlideMenu;
import china.wc.tallyhelper.controls.SlideMenuItem;
import china.wc.tallyhelper.model.ModelBook;

public class ActivityStatistics extends ActivityFrame implements OnItemClickListener
{
    public static final String             SELECTED_MODEL_OBJECT        = "ModelBook";
    
    private AdapterListViewBookList mAdapterListViewBookList;
    
    private ListView mFramebodyStatistics_ListView_BookList;
    
    private ModelBook mSelectedBook;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // 载入主页面Layout文件
        loadFramebody(R.layout.framebody_statistics);
        // 设置标题
        setTopTitle(R.string.title_statistics);
        
        executeInitTask(null);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        mSelectedBook = mAdapterListViewBookList.getItem(position);
        Bundle _Bundle = new Bundle();
        _Bundle.putSerializable(SELECTED_MODEL_OBJECT, mSelectedBook);
        openActivity(ActivityStatisticsBookDetail.class, _Bundle);
    }

    @Override
    public void onSlideMenuItemClick(SlideMenu pSlideMenu, SlideMenuItem pSlideMenuItem, AdapterView<?> pParent, View pView, int pPosition, long pId)
    {
    }

    @Override
    protected void initFields()
    {
        mAdapterListViewBookList = new AdapterListViewBookList(this);
    }

    @Override
    protected void initViews()
    {
        mFramebodyStatistics_ListView_BookList = (ListView) findViewById(R.id.FramebodyStatistics_ListView_BookList);
        mFramebodyStatistics_ListView_BookList.setEmptyView(findViewById(R.id.FramebodyStatistics_LinearLayout_Empty));
    }

    @Override
    protected void initListeners()
    {
        mFramebodyStatistics_ListView_BookList.setOnItemClickListener(this);
    }

    @Override
    protected void bindData()
    {
        mFramebodyStatistics_ListView_BookList.setAdapter(mAdapterListViewBookList);
    }

    @Override
    protected void register()
    {
    }
    
    @Override
    protected Object doInBackground(Object... params)
    {
        initFields();
        return null;
    }

    @Override
    protected void onPostExecute(Object result)
    {
        super.onPostExecute(result);
        initViews();
        initListeners();
        bindData();
        register();
    }
    
}
